package projectsupporter.common.formbase.progrees;

import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.ProgressBar;

import projectsupporter.common.control.Path;

public class ProgressBarDialog {

	private Shell sShell = null;  //  @jve:decl-index=0:visual-constraint="10,10"
	private Composite composite = null;
	private CLabel cLabel = null;
	private CLabel actionNameLabel = null;
	private ProgressBar progressBar = null;
	private CLabel detialNameLabel = null;
	private CLabel detialInfoLabel = null;
	
	private Shell parentShell;
	private boolean disposed;

	public ProgressBarDialog(Shell parentShell)
	{
		this.parentShell=parentShell;
		createSShell() ;
	}
	
	/**
	 * This method initializes sShell
	 */
	private void createSShell() {
		if(parentShell==null)
		{
			sShell = new Shell();
		}
		else
		{
			sShell = new Shell(parentShell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		}

		sShell.setText("Shell");
		createComposite();
		sShell.setSize(new Point(567, 200));
		sShell.setLayout(new FillLayout());
	}

	/**
	 * This method initializes composite	
	 *
	 */
	private void createComposite() {
		GridData gridData3 = new GridData();
		gridData3.grabExcessHorizontalSpace = true;
		gridData3.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
		gridData3.horizontalSpan = 2;
		GridData gridData2 = new GridData();
		gridData2.horizontalSpan = 2;
		gridData2.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
		gridData2.grabExcessHorizontalSpace = true;
		GridData gridData1 = new GridData();
		gridData1.horizontalSpan = 2;
		gridData1.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
		gridData1.heightHint = 30;
		gridData1.grabExcessHorizontalSpace = true;
		GridData gridData = new GridData();
		gridData.grabExcessHorizontalSpace = true;
		gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 2;
		gridLayout.marginWidth = 10;
		gridLayout.verticalSpacing = 0;
		gridLayout.marginHeight = 10;
		composite = new Composite(sShell, SWT.NONE);
		composite.setLayout(gridLayout);
		cLabel = new CLabel(composite, SWT.NONE);
		cLabel.setText("CLabel");
		actionNameLabel = new CLabel(composite, SWT.NONE);
		actionNameLabel.setText(" ");
		actionNameLabel.setLayoutData(gridData);
		progressBar = new ProgressBar(composite, SWT.NONE);
		progressBar.setLayoutData(gridData1);
		detialNameLabel = new CLabel(composite, SWT.NONE);
		detialNameLabel.setText(" ");
		detialNameLabel.setLayoutData(gridData2);
		detialInfoLabel = new CLabel(composite, SWT.NONE);
		detialInfoLabel.setText(" ");
		detialInfoLabel.setLayoutData(gridData3);
	}
	
	public void setMax(int max)
	{
		this.progressBar.setMaximum(max);
	}
	
	public void setMin(int min)
	{
		this.progressBar.setMinimum(min);
	}
	
	public void setValue(int value)
	{
		this.progressBar.setSelection(value);
//		if(this.progressBar.isDisposed()||this.progressBar.getSelection()==this.progressBar.getMaximum())
//		{
//			this.close();
//		}
	}
	
	public void setActionName(String actionName)
	{
		this.actionNameLabel.setText(actionName);
	}
	
	public void setDetialName(String detialName)
	{
		this.detialNameLabel.setText(detialName);
	}
	
	public void setDetialInfo(String detialInfo)
	{
		this.detialInfoLabel.setText(detialInfo);
	}
	
	/**
	 * 打开文件夹选择对话框
	 */
	public void open() {
		sShell.open();// 打开文件夹选择窗口
		sShell.layout();
	}
	
	/**
	 * 关闭文件夹选择对话框
	 */
	public void close() {
		if(this.progressBar.isDisposed()==false)
		{
			this.progressBar.setSelection(this.progressBar.getMaximum());
		}
		if (sShell != null)
			sShell.dispose();// 释放底层的资源
	}
	

	public Shell getParentShell() {
		return parentShell;
	}

	public void setParentShell(Shell parentShell) {
		this.parentShell = parentShell;
	}

	public boolean isDisposed() {
		return disposed;
	}

	public void setDisposed(boolean disposed) {
		this.disposed = disposed;
	}

	public ProgressBar getProgressBar() {
		return progressBar;
	}

	
	
	
}
